package dice.sinanya.dice.manager;

import com.forte.qqrobot.beans.messages.result.inner.Group;
import com.forte.qqrobot.beans.messages.result.inner.GroupMember;
import dice.sinanya.dice.MakeNickToSender;
import dice.sinanya.dice.imal.Check;
import dice.sinanya.entity.EntityGroupSwitch;
import dice.sinanya.entity.EntityTypeMessages;
import dice.sinanya.entity.EntityWelcome;
import dice.sinanya.entity.imal.AlgorithmTypes;
import dice.sinanya.exceptions.*;
import dice.sinanya.tools.getinfo.GetGroupInfo;
import dice.sinanya.tools.makedata.ReplyFromXml;
import org.dom4j.DocumentException;
import org.nlpcn.commons.lang.util.StringUtil;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;

import static dice.sinanya.db.groupSwitch.InputGroupSwitch.insertGroupSwitch;
import static dice.sinanya.db.system.InsertBot.deleteBot;
import static dice.sinanya.db.system.SelectBot.flushBotList;
import static dice.sinanya.db.system.SelectBot.selectBotList;
import static dice.sinanya.system.MessagesBanList.groupSwitchHashMap;
import static dice.sinanya.system.MessagesBanList.qqBanList;
import static dice.sinanya.system.MessagesSystem.NONE;
import static dice.sinanya.system.MessagesSystem.loginInfo;
import static dice.sinanya.system.MessagesTag.*;
import static dice.sinanya.system.MessagesWelcome.welcomes;
import static dice.sinanya.tools.checkdata.CheckCantInPrivate.checkCantInPrivate;
import static dice.sinanya.tools.checkdata.CheckIsNumbers.isNumeric;
import static dice.sinanya.tools.checkdata.imal.GetZk.clearGroupActive;
import static dice.sinanya.tools.getinfo.GetMessagesProperties.*;
import static dice.sinanya.tools.getinfo.GetNickName.getGroupName;
import static dice.sinanya.tools.getinfo.SwitchBot.getBot;
import static dice.sinanya.tools.getinfo.Welcome.insertWelcome;
import static dice.sinanya.tools.makedata.MakeMessages.deleteTag;
import static dice.sinanya.tools.makedata.Sender.sender;
import static dice.sinanya.tools.makedata.StringFormatById.stringFormatById;
import static java.lang.Math.ceil;

/**
 * @author SitaNya
 * @date 2019/9/11
 * @email sitanya@qq.com
 * @qqGroup 162279609
 * 有任何问题欢迎咨询
 * <p>
 * 类说明:
 */
public class GroupManager implements MakeNickToSender, Check {
    private final EntityTypeMessages entityTypeMessages;

    public GroupManager(EntityTypeMessages entityTypeMessages) {
        this.entityTypeMessages = entityTypeMessages;
    }

    String enableSwitch = "1";
    String disableSwitch = "0";

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void jrrp() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_JRRP;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean jrrp = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setJrrp(jrrp);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (jrrp) {
                sender(entityTypeMessages, entityGame.getJrrpStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getJrrpStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void npc() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_NPC;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean npc = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setNpc(npc);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (npc) {
                sender(entityTypeMessages, entityGame.getNpcStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getNpcStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void welcome() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_WELCOME;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean boolWelcome = enableSwitch.equals(msg);
            EntityWelcome thisWelcomes = welcomes.getOrDefault(groupId, new EntityWelcome(false, ""));
            thisWelcomes.setEnable(boolWelcome);
            welcomes.put(groupId, thisWelcomes);
            insertWelcome(groupId, thisWelcomes);
            if (boolWelcome) {
                sender(entityTypeMessages, entityGame.getWelcomeStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getWelcomeStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void gas() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_GAS;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean gas = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setGas(gas);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (gas) {
                sender(entityTypeMessages, entityGame.getGasStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getGasStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void bg() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_BG;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean bg = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setBg(bg);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (bg) {
                sender(entityTypeMessages, entityGame.getBgStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getBgStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void tz() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_TZ;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean tz = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setTz(tz);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (tz) {
                sender(entityTypeMessages, entityGame.getTzStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getTzStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void simple() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_SIMPLE;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean simple = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setSimple(simple);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (simple) {
                try {
                    new ReplyFromXml("").flushMap();
                } catch (DocumentException | ReplyTooShortException e) {
                    e.printStackTrace();
                }
                sender(entityTypeMessages, entityGame.getSimpleStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getSimpleStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void ob() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_OB;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean ob = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setOb(ob);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (ob) {
                sender(entityTypeMessages, entityGame.getObStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getObStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void deck() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_DECK;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean deck = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setDeck(deck);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (deck) {
                sender(entityTypeMessages, entityGame.getDeckStart(entityTypeMessages.getFromGroupString()));
            } else {
                sender(entityTypeMessages, entityGame.getDeckStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    public void setZookeeper() throws OnlyManagerException, CantInPrivateException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        if (!entitySystemProperties.isZookeeper()) {
            sender(entityTypeMessages, entityGame.getRankCantStart(entityTypeMessages.getFromGroupString()));
            return;
        }
        String tag = TAG_GROUP_ZOOKEEPER;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 2));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean zookeeper = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setZookeeper(zookeeper);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (zookeeper) {
                sender(entityTypeMessages, entityGame.getRankStart(entityTypeMessages.getFromGroupString()));
            } else {
                clearGroupActive();
                sender(entityTypeMessages, entityGame.getRankStop(entityTypeMessages.getFromGroupString()));
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    public void setRule() throws OnlyManagerException, CantInPrivateException, SetRuleFormatException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_RULE_SET;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 2));
        if (!isNumeric(msg)) {
            throw new SetRuleFormatException(entityTypeMessages);
        }

        if (Integer.parseInt(msg) > 10 || Integer.parseInt(msg) < 1) {
            throw new SetRuleFormatException(entityTypeMessages);
        }

        long groupId = entityTypeMessages.getFromGroup();
        int rule = Integer.parseInt(msg);
        EntityGroupSwitch entityGroupSwitch;
        if (groupSwitchHashMap.containsKey(groupId)) {
            entityGroupSwitch = groupSwitchHashMap.get(groupId);
        } else {
            entityGroupSwitch = new EntityGroupSwitch();
        }
        entityGroupSwitch.setRule(rule);
        groupSwitchHashMap.put(groupId, entityGroupSwitch);
        insertGroupSwitch(entityGroupSwitch, groupId);
        sender(entityTypeMessages, stringFormatById(entityGame.getRuleChange(entityTypeMessages.getFromGroupString()), rule, (100 - rule + 1), rule));
    }

    public void getRule() throws CantInPrivateException {
        checkCantInPrivate(entityTypeMessages);
        long groupId = entityTypeMessages.getFromGroup();
        if (groupSwitchHashMap.containsKey(groupId)) {
            EntityGroupSwitch entityGroupSwitch = groupSwitchHashMap.get(groupId);
            int rule = entityGroupSwitch.getRule();
            sender(entityTypeMessages, stringFormatById(entityGame.getRuleGet(entityTypeMessages.getFromGroupString()), rule, (100 - rule + 1), rule));
        } else {
            sender(entityTypeMessages, entityGame.getRuleDefault(entityTypeMessages.getFromGroupString()));
        }
    }

    public void setAlgorithm() throws OnlyManagerException, CantInPrivateException, SetAlgorithmTypeException {
        checkAudit(entityTypeMessages);
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_ALGO_SET;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 2));
        if (!isNumeric(msg)) {
            throw new SetAlgorithmTypeException(entityTypeMessages);
        }

        if ((Integer.parseInt(msg) < 1 || Integer.parseInt(msg) > 3) && Integer.parseInt(msg) != 187099872) {
            throw new SetAlgorithmTypeException(entityTypeMessages);
        }

        long groupId = entityTypeMessages.getFromGroup();
        int algorithmType = Integer.parseInt(msg);
        if (algorithmType == 187099872 && entityTypeMessages.getFromQq() != 187099872) {
            sender(entityTypeMessages, "只有熊哥可以开启这个亲友团算法，算法类型修改失败");
            return;
        }
        EntityGroupSwitch entityGroupSwitch;
        if (groupSwitchHashMap.containsKey(groupId)) {
            entityGroupSwitch = groupSwitchHashMap.get(groupId);
        } else {
            entityGroupSwitch = new EntityGroupSwitch();
        }
        entityGroupSwitch.setAlgorithmTypes(AlgorithmTypes.getValueByCode(algorithmType));
        groupSwitchHashMap.put(groupId, entityGroupSwitch);
        insertGroupSwitch(entityGroupSwitch, groupId);
        sender(entityTypeMessages, "本群骰点算法已改变为:\n" + algorithmType + ":\t" + AlgorithmTypes.getValueByCode(algorithmType).getInfo());
    }

    public void getAlgorithm() throws CantInPrivateException {
        checkCantInPrivate(entityTypeMessages);
        long groupId = entityTypeMessages.getFromGroup();
        if (groupSwitchHashMap.containsKey(groupId)) {
            EntityGroupSwitch entityGroupSwitch = groupSwitchHashMap.get(groupId);
            int algorithmType = entityGroupSwitch.getAlgorithmTypes().getTypeId();
            sender(entityTypeMessages, "本群当前骰点算法为:\n" + algorithmType + ":\t" + AlgorithmTypes.getValueByCode(algorithmType).getInfo());
        } else {
            sender(entityTypeMessages, "本群当前骰点算法为:\n2:\t符合预期算法");
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void secret() throws CantInPrivateException {
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_SECRET;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean secret = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setSecret(secret);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (secret) {
                sender(entityTypeMessages, "秘密团模式已在本群开启");
            } else {
                sender(entityTypeMessages, "秘密团模式已在本群关闭");
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }

    /**
     * 设定kp主群，由于基本不造成影响，所以不做删除了
     */
    public void reply() throws CantInPrivateException {
        checkCantInPrivate(entityTypeMessages);
        String tag = TAG_GROUP_REPLY;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 5));
        long groupId = entityTypeMessages.getFromGroup();
        if (enableSwitch.equals(msg) || disableSwitch.equals(msg)) {
            boolean reply = enableSwitch.equals(msg);
            EntityGroupSwitch entityGroupSwitch;
            if (groupSwitchHashMap.containsKey(groupId)) {
                entityGroupSwitch = groupSwitchHashMap.get(groupId);
            } else {
                entityGroupSwitch = new EntityGroupSwitch();
            }
            entityGroupSwitch.setReply(reply);
            groupSwitchHashMap.put(groupId, entityGroupSwitch);
            insertGroupSwitch(entityGroupSwitch, groupId);
            if (reply) {
                sender(entityTypeMessages, "自定义回复已在本群开启");
            } else {
                sender(entityTypeMessages, "自定义回复已在本群关闭");
            }
        } else {
            sender(entityTypeMessages, entityGame.getGroupSwitchInfo(entityTypeMessages.getFromGroupString()));
        }
    }


    public void get() throws CantInPrivateException {
        checkCantInPrivate(entityTypeMessages);
        String disable = "禁用";
        String enable = "启用";
        String disableBySimple = "因Simple模式而禁用";
        String jrrpEnable = disable;
        String welcomeEnable = disable;
        String welcomeSet = disable;
        String deckEnable = disable;
        String botListEnable = disable;
        if (entityGame.isJrrpSwitch()) {
            jrrpEnable = enable;
        }
        if (entityGame.isWelcomeSwitch()) {
            welcomeEnable = enable;
        }

        if (welcomes.containsKey(entityTypeMessages.getFromGroup()) && !welcomes.get(entityTypeMessages.getFromGroup()).getText().equals(NONE)) {
            welcomeSet = "已设置";
        }

        if (entityGame.isDeck()) {
            deckEnable = enable;
        }

        if (entityGame.isBotList()) {
            botListEnable = enable;
        }

        String jrrpGroup = enable;
        String npcGroup = enable;
        String welcomeGroup = enable;
        String gasGroup = enable;
        String bgGroup = enable;
        String tzGroup = enable;
        String simpleGroup = disable;
        String obGroup = enable;
        String deckGroup = enable;
        String zookeeperGroup = enable;
        String reply=enable;

        String secretGroup = enable;

        if (groupSwitchHashMap.containsKey(entityTypeMessages.getFromGroup())) {
            EntityGroupSwitch entityGroupSwitch = groupSwitchHashMap.get(entityTypeMessages.getFromGroup());
            if (!entityGroupSwitch.isJrrp()) {
                jrrpGroup = disable;
            }

            if (!entityGroupSwitch.isNpc()) {
                npcGroup = disable;
            }

            if (!welcomes.containsKey(entityTypeMessages.getFromGroup())) {
                welcomeGroup = disable;
            }

            if (!entityGroupSwitch.isGas()) {
                gasGroup = disable;
            }

            if (!entityGroupSwitch.isBg()) {
                bgGroup = disable;
            }

            if (!entityGroupSwitch.isTz()) {
                tzGroup = disable;
            }

            if (!entityGroupSwitch.isSecret()) {
                secretGroup = disable;
            }

            if (!entityGroupSwitch.isReply()){
                reply=disable;
            }

            if (!entityGroupSwitch.isSimple()) {
                simpleGroup = disable;
            } else {
                simpleGroup = enable;
                jrrpGroup = disableBySimple;
                npcGroup = disableBySimple;
                gasGroup = disableBySimple;
                bgGroup = disableBySimple;
                tzGroup = disableBySimple;
                deckGroup = disableBySimple;
                reply=disableBySimple;
            }

            if (!entityGroupSwitch.isOb()) {
                obGroup = disable;
            }

            if (!entityGroupSwitch.isDeck()) {
                deckGroup = disable;
            }

            if (!entityGroupSwitch.isZookeeper()) {
                zookeeperGroup = disable;
            }
        }

        GroupMember[] members = entityTypeMessages.getMsgSender().GETTER.getGroupMemberList(entityTypeMessages.getFromGroupString()).getList();
        int fishMembers = 0;
        StringBuilder banInGroup = new StringBuilder();
        for (GroupMember member : members) {
            long lastMsgForNow = System.currentTimeMillis() - member.getLastTime();
            if (lastMsgForNow / 1000 > 30 * 60 * 60 * 24) {
                fishMembers++;
            }
            if (qqBanList.containsKey(String.valueOf(member.getQQ()))) {
                banInGroup.append("\n").append(makeNickToSender(String.valueOf(member.getQQ()))).append("(").append(member.getNickname()).append(")");
            }
        }
        String info = "群名:\t" +
                makeGroupNickToSender(getGroupName(entityTypeMessages)) +
                "\n" +
                "群号:\t" +
                entityTypeMessages.getFromGroupString() +
                "\n" +
                loginInfo.getLoginName() + "在本群状态:\t" +
                getBot(entityTypeMessages.getFromGroup()) +
                "\n" +
                "jrrp全局开关:\t" +
                jrrpEnable +
                "\n" +
                "jrrp本群开关:\t" +
                jrrpGroup +
                "\n" +
                "welcome全局开关:\t" +
                welcomeEnable +
                "\n" +
                "welcome本群开关:\t" +
                welcomeGroup +
                "\n" +
                "welcome信息:\t" +
                welcomeSet +
                "\n" +
                "deck全局开关:\t" +
                deckEnable +
                "\n" +
                "deck本群开关:\t" +
                deckGroup +
                "\n" +
                "dicelist全局开关:\t" +
                botListEnable +
                "\n" +
                "npc本群开关:\t" +
                npcGroup +
                "\n" +
                "gas本群开关:\t" +
                gasGroup +
                "\n" +
                "bg本群开关:\t" +
                bgGroup +
                "\n" +
                "tz本群开关:\t" +
                tzGroup +
                "\n" +
                "simple本群开关:\t" +
                simpleGroup +
                "\n" +
                "ob本群开关:\t" +
                obGroup +
                "\n" +
                "rank(抢占)本群开关:\t" +
                zookeeperGroup +
                "\n" +
                "秘密团模式本群开关:\t" +
                secretGroup +
                "\n" +
                "自定义回复词本群开关:\t" +
                reply +
                "\n" +
                "30天不活跃群员数:\t" +
                fishMembers +
                "\n" +
                "群内黑名单成员:\t" +
                banInGroup;
        sender(entityTypeMessages, info);
    }

    public void groupList() throws NotMasterException {
        if (!entityBanProperties.getMaster().contains(entityTypeMessages.getFromQqString())) {
            throw new NotMasterException(entityTypeMessages);
        }
        String tag = TAG_GROUP_LIST;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 2));
        sender(entityTypeMessages, "此命令可能需要较长时间才能回复，通常在10分钟以内，期间不会影响其他功能使用，请耐心等待");
        int index = 1;
        if (isNumeric(msg)) {
            index = Integer.parseInt(msg);
        }
        Group[] groups = entityTypeMessages.getMsgSender().GETTER.getGroupList().getList();
        ArrayList<String> collect = (ArrayList<String>) Arrays.stream(groups).parallel().map(s -> new GetGroupInfo(entityTypeMessages.getMsgSender().GETTER.getGroupInfo(s.getCode())).call()).collect(Collectors.toList());
        int pages = (int) ceil(collect.size() * 1.0 / 10);
        if (index > pages) {
            sender(entityTypeMessages, "您指定的页码数大于总页数");
            return;
        }
        if (pages == 1) {
            sender(entityTypeMessages, "本骰共加入以下群组:\n" + StringUtil.joiner(collect, "\n"));
        } else {
            ArrayList<String> result = new ArrayList<>();
            int a = 1;
            for (int i = (index - 1) * 10; i < collect.size(); i++) {
                result.add(collect.get(i));
                a++;
                if (a == 10) {
                    break;
                }
            }
            sender(entityTypeMessages, "本骰共加入以下群组:(共有" + collect.size() + "项，共计" + pages + "页" + "当前显示为第" + index + "页)\n" + StringUtil.joiner(result, "\n"));
        }
        flushBotList(entityTypeMessages.getMsgSender());
    }

    public void groupSearch() throws NotFoundGroupException, BanListInputNotIdException, NotMasterException {
        if (!entityBanProperties.getMaster().contains(entityTypeMessages.getFromQqString())) {
            throw new NotMasterException(entityTypeMessages);
        }
        String tag = TAG_GROUP_SEARCH;
        String msg = deleteTag(entityTypeMessages.getMsgGet().getMsg(), tag.substring(0, tag.length() - 4));
        if (!isNumeric(msg)) {
            throw new BanListInputNotIdException(entityTypeMessages);
        }
        long groupId = Long.parseLong(msg);
        String name = getGroupName(entityTypeMessages.getMsgSender(), String.valueOf(groupId));
//        int memberSize = coolQ.getGroupInfo(groupId, false).getCount();
        if ("".equals(name)) {
            throw new NotFoundGroupException(entityTypeMessages);
        }
        sender(entityTypeMessages, "群号: " + groupId + "\t群名: ");
//        + name + "\t共有成员: " + memberSize + "名"
    }

    public void groupClean() throws NotMasterException {
        if (!entityBanProperties.getMaster().contains(entityTypeMessages.getFromQqString())) {
            throw new NotMasterException(entityTypeMessages);
        }
        ArrayList<Long> botList = selectBotList();

        Group[] groupList = entityTypeMessages.getMsgSender().GETTER.getGroupList().getList();
        ArrayList<Long> groupListCode = new ArrayList<>();
        for (Group group : groupList) {
            groupListCode.add(Long.valueOf(group.getCode()));
        }

        for (long botGroupIdString : botList) {
            if (!groupListCode.contains(botGroupIdString)) {
                deleteBot(botGroupIdString);
                for (String masterId : entityBanProperties.getMaster()) {
                    entityTypeMessages.getMsgSender().SENDER.sendPrivateMsg(masterId, "删除已不存在群： " + botGroupIdString);
                }
            }
        }
    }
}
